package org.operator.entity.orm;

import java.lang.reflect.Field;
import java.util.List;
import java.util.Map;

import org.operator.OperatorDb;
import org.operator.conn.conf.ConfigDbConfig;
import org.operator.impl.BaseOperatorDb;
import org.until.FirstToUpper;

public class MappingAssignment {
	
	private String className;
	
	private OperatorDb oprea;
	
	
	/**
	 * @param className
	 */
	public MappingAssignment(String className) {
		
		this.className = FirstToUpper.getInstance(className).upperCase();
		
		this.oprea = new BaseOperatorDb(this.className);
	}
	
	
	public Object reflectionValue()
	{
		String className = ConfigDbConfig.getInstance("system").getSystemConf().get("db_colum_package")+"."+ this.className;
		
		try {
			
			Object obj = Class.forName(className).newInstance();
			
			Field [] field = obj.getClass().getDeclaredFields();
		
			List<Map<String, Object>> colum = this.oprea.getTableCoulum();  
			
			for(int i = 0; i < field.length; i++) {
				
				field[i].setAccessible(true);
				
				field[i].set(obj, colum.get(i).get("COLUMN_NAME"));
			}
			
			return obj;
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return null;
	}
	
}
